<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>滴答办公系统-学员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/media/layui/css/layui.css" media="all">
    <script src="/media/js/jquery.min.js"></script>
</head>
<body>
<div class="layui-container">
    <div class="layui-row" style="margin-top: 10px">
        <form action="/studentPageList/1/${pageUtils.pageSize}" method="post" id="aa">
            <div class="layui-col-xs3" style="margin-right: 20px">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" id="no" name="name" class="layui-input" placeholder="学生姓名">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3" style="margin-right: 20px">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">班级：</label>
                    <div class="layui-input-block">
                        <select class="layui-input" id="fg" name="classId">
                            <!--<option value="-1">请选择班级</option>-->
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs2">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn"><i class="layui-icon layui-icon-search">搜索</i></button>
                    </div>
                </div>
            </div>
        </form>
        <div class="layui-col-xs2">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <a class="layui-btn layui-btn-mini layui-btn-mini" href="javascript:excelexport();"
                       lay-event="detail">导出Excel</a>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="layui-container">
    <table class="layui-table" id="tbdata" lay-filter="tbop">
        <thead>
        <tr>
            <td>学号</td>
            <td>姓名</td>
            <td>班级</td>
            <td>性别</td>
            <td>手机号</td>
            <td>邮箱</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${pageUtils.recordsl}" var="stu">
            <tr>
                <td>${stu.id}</td>
                <td>${stu.name}</td>
                <td>${stu.TClass.className}</td>
                <td>${stu.sex}</td>
                <td>${stu.phone}</td>
                <td>${stu.email}</td>
                <td><a class="layui-btn layui-btn-mini" href="studentupdate.html">编辑</a>
                    <a class="layui-btn layui-btn-mini layui-btn-mini" href="studentdetails.html" lay-event="detail">查看详情</a>
                    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del"
                       onclick="deleteCourse(${stu.id},${pageUtils.pageIndex},${pageUtils.pageSize});">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
        <c:if test="${pageUtils.pageIndex==1}">
            <a href="#"
               class="layui-laypage-prev layui-disabled" data-page="0">
                <i class="layui-icon">&lt;</i>
            </a>
        </c:if>
        <c:if test="${pageUtils.pageIndex!=1}">
            <a href="/studentPageList/${pageUtils.pageIndex-1}/${pageUtils.pageSize}"
               class="layui-laypage-prev " data-page="0">
                <i class="layui-icon">&lt;</i>
            </a>
        </c:if>

        <c:forEach begin="${pageUtils.numberStart}" end="${pageUtils.numberEnd}" var="num" step="1">
            <a href="/studentPageList/${num}/${pageUtils.pageSize}?name=${requestScope.name}&classId=${requestScope.classId}">${num}</a>
        </c:forEach>

        <c:if test="${pageUtils.pageIndex!=pageUtils.pageCount}">
            <a href="/studentPageList/${pageUtils.pageIndex+1}/${pageUtils.pageSize}"
               class="layui-laypage-next " data-page="2">
                <i class="layui-icon">&gt;</i>
            </a>
        </c:if>
        <c:if test="${pageUtils.pageIndex==pageUtils.pageCount}">
            <a href="#"
               class="layui-laypage-next layui-disabled" data-page="2">
                <i class="layui-icon">&gt;</i>
            </a>
        </c:if>

        <span class="layui-laypage-skip">到第
							   <input type="text" min="1" value="${pageUtils.pageIndex}" class="layui-input"
                                      id="pageText">页
								<button type="button" class="layui-laypage-btn" onclick="pageBtn()">确定</button>
							</span>
        <span class="layui-laypage-count">共 ${pageUtils.allCount} 条  当前第${pageUtils.pageIndex}页/共${pageUtils.pageCount}页</span>
        <span class="layui-laypage-limits">
							    <select lay-ignore="" onchange="toPage(this)" id="select">
							        <option value="5" ${pageUtils.pageSize==5?"selected":""}>5 条/页</option>
									<option value="10" ${pageUtils.pageSize==10?"selected":""}>10 条/页</option>
									<option value="15" ${pageUtils.pageSize==15?"selected":""}>15 条/页</option>
								</select>
							</span>
    </div>
</div>

<script src="/media/layui/layui.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.4.3/layui.all.js"></script>


<script type="text/javascript">
    function deleteCourse(id, ind, size) {
        layui.use('table', function () {
            layer.confirm('是否确认删除学生?', function (index) {
                $.getJSON("/deletedStudent", {"id": id}, function (result) {
                    if (result.status == 200) {
                        layer.msg(result.message);
                        setTimeout(function () {
                            location.href = "/studentPageList/" + ind + "/" + size + "?name=${requestScope.name}&classId=${requestScope.classId}"
                        }, 600);
                    } else {
                        layer.msg(result.message);
                    }
                });
            });
        });
    }
</script>
<script>

    // 分页大小调整
    function toPage(th) {
        location.href = "/studentPageList/1/" + th.value + "?name=${requestScope.name}&classId=${requestScope.classId}";
    }

    //按钮跳转页面
    function pageBtn() {
        console.log($("#select").val())
        if ($('#pageText').val() <= ${pageUtils.pageCount}) {
            location.href = "/studentPageList/" + $('#pageText').val() + "/" + $("#select").val() + "?name=${requestScope.name}&classId=${requestScope.classId}";

        } else {
            layer.msg("请重新输入");
            $('#pageText').val("")
        }

    }


    //绑定班级选择下拉框
    $.getJSON("/getAllClass", function (arr) {
        $("#fg").append("<option value='0'>--请选择班级--</option>");
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].id ==${classId}) {
                $("#fg").append("<option selected value='" + arr[i].id + "'>" + arr[i].className + "</option>");
            } else {
                $("#fg").append("<option  value='" + arr[i].id + "'>" + arr[i].className + "</option>");
            }
        }
    });

    //固定

    //导数据到excel
    function excelexport(){
        var url="/exportexcel";
        $("#aa").prop("action",url);
        $("#aa").submit();
    }

</script>

</body>
</html>